
from django.shortcuts import render,HttpResponse,redirect
from stuInfo.models import StudentInfo,College,Counselor, CarInfo, CancelCarInfo
import pandas as pd
from django.db import transaction


def operation_database(request):
    # # 读取学生信息
    # df = pd.read_excel("D:\\00石金峰\\django_learn\\mysite1\\src\\mysite\\stuInfo\\datasets\\学生基本信息管理(2024.12.2最新).xlsx")
    # data = df.to_records("record")
    # # 删除数据库所有内容
    # # StudentInfo.objects.all().delete()
    # # 写入数据库内容
    # students = []
    # for info in data:
    #     StudentInfo(
    #         学号=info[1],
    #         姓名=info[2],
    #         性别=info[3],
    #         上课院系=info[4],
    #         专业号=info[5],
    #         专业名称=info[6],
    #         班级=info[7],
    #         学制=info[8],
    #         当前所在级=info[9],
    #         出生日期=info[10],
    #         身份证件号=info[11],
    #         考生号=info[12],
    #         入学年份=info[13],
    #         在校状态=info[14],
    #         学籍状态=info[15],
    #         学生当前状态=info[16],
    #         入学日期=info[17],
    #         培养层次=info[18],
    #         民族=info[19]
    #         )
    #     students.append(info)
    # StudentInfo.objects.bulk_create(students)
    '''
    添加学院信息
    ("ND","能源与动力工程学院"),
    ("JZ","计算机与人工智能学院"),
    ("SG","数字经济与管理学院"),
    ("RW","人文学院"),
    ("JY","教育学院"),
    ("YS","艺术学院"),
    ("CM","传媒学院"),
    '''
    # College.objects.create(college='ND')
    # College.objects.create(college='JZ')
    # College.objects.create(college='SG')
    # College.objects.create(college='RW')
    # College.objects.create(college='JY')
    # College.objects.create(college='YS')
    # College.objects.create(college='CM')

    # # 生成辅导员信息信息
    # df = pd.read_excel("D:\\00石金峰\\django_learn\\mysite1\\src\\mysite\\stuInfo\\datasets\\辅导员信息表汇总.xlsx",sheet_name="teacher")
    # df.fillna('')
    # data = df.to_records("record")
    # for info in data:
    #     Counselor.objects.create(
    #         name=info[2],
    #         gender=info[3],
    #         college_id=info[4],
    #         # birthdate=info[5],
    #         # nationality=info[6],
    #         # political_affiliation=info[7],
    #         # graduate_school=info[8],
    #         # major=info[9],
    #         # degree=info[10],
    #         # enter_time=info[11],
    #         phone_number=info[12],
    #         )

    # 添加车辆信息表
    # CarInfo.objects.create(
    #     department="后勤保卫处",
    #     dep_detail = None,
    #     name="aaaa",
    #     car_number = '宁Adgdggd',
    #     phone_number = '15500802551',
    #     south_gate = False,
    #     east_gate = True,
    #     west_gate = True,
    #     southeast_gate = True,
    #     create_date = "2024-10-8",
    #     due_date ="2025-10-8",
    #     category=1,
    #     notes = None
    # )

    # 批量授权
    # CarInfo.objects.filter(category=1).update(south_gate=True)
    # CarInfo.objects.all().update(south_gate=False)

    # 年份统一加一
    # from django.db.models import F
    # from django.db.models.expressions import Value
    # from datetime import timedelta
    # CarInfo.objects.filter(category=1).update(due_date = F('due_date')+timedelta(days=365))


    return render(request,"database_operations.html")